/<template>
  <div v-show="visiable" class="drawer-box-wrapper bottom-box">
    <div class="taskCase_container_table">
      <div class="taskCase_container_tabletop">
        <h2>元任务列表</h2>
      </div>

      <el-table
        v-loading="tableLoading"
        :data="tableData"
        style="width: 100%"
        stripe
        class="mainTable"
        height="35vh"
        @selection-change="handleSelectionChange"
        ref="multipleTable"
      >
        <el-table-column type="selection" width="50" />
        <el-table-column label="序号" type="index" width="50" />
        <el-table-column show-overflow-tooltip label="需求编号" prop="xqbh" />
        <el-table-column
          show-overflow-tooltip
          label="元任务编号"
          prop="yrwbh"
        />
        <el-table-column show-overflow-tooltip label="目标编号" prop="mbbh" />

        <el-table-column show-overflow-tooltip label="目标经度" prop="mbjd" />
        <el-table-column show-overflow-tooltip label="目标纬度" prop="mbwd" />
        <el-table-column show-overflow-tooltip label="卫星标识" prop="wxbs" />
        <el-table-column
          show-overflow-tooltip
          label="传感器标识"
          prop="cgqbs"
        />

        <el-table-column show-overflow-tooltip label="优先级" prop="yxj" />
        <el-table-column
          show-overflow-tooltip
          label="观测开始时间"
          prop="kssj"
        />
        <el-table-column
          show-overflow-tooltip
          label="观测结束时间"
          prop="jssj"
        />
        <el-table-column
          show-overflow-tooltip
          label="中心点访问时刻"
          prop="zxdfwsk"
        />

        <el-table-column show-overflow-tooltip label="侧摆角" prop="cbj" />
        <el-table-column
          show-overflow-tooltip
          label="太阳高度角"
          prop="tygdj"
        />
      </el-table>
      <div class="taskCase_container_tablebut">
        <div>
          <span>选择规划模型：</span>
          <el-input class="tasc_input" placeholder=""></el-input>
          <el-button type="primary" size="small" @click="handleOpenModal"
            >任务规划</el-button
          >
        </div>
        <!-- <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="queryParam.pageCurrent"
          :page-size="queryParam.pageSize"
          layout="prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination> -->
      </div>
    </div>

    <footer-modal ref="footerRef" @callback="childCallback" />
  </div>
</template>

<script>
import { GetMetaTaskList } from '@/api/taskPlanning/index.js'
import FooterModal from './modal/footermodal.vue'
export default {
  components: {
    FooterModal
  },
  data() {
    return {
      visiable: false,
      queryParam: {
        // pageSize: 10,
        // pageCurrent: 1,
        tjTime: null,
        xqbh: null
      },
      tableData: [],
      tableLoading: false,
      total: 0,
      multipleSelection: [],
      isAuto: false
    }
  },
  mounted() {
    this.$bus.$on('automationActionBottom', data => {
      this.queryParam.tjTime = data.tjTime
      this.queryParam.xqbh = data.xqbh
      this.visiable = true
      this.$store.dispatch('drawer/setbottomvisible', true)

      this.GetMetaTaskList(this.queryParam, data.flag)
    })
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val
    },

    childCallback(data, formValue) {
      console.log(data)
    },

    // 打开模型弹窗
    handleOpenModal(flag = false) {
      // 自动化，就存储下来
      if (flag == true) {
        this.$refs.footerRef.openModal(this.tableData, flag)
        return
      }

      if (this.multipleSelection.length === 0) {
        this.$message.warning('请选择元任务')
        return
      }
      this.$refs.footerRef.openModal(this.multipleSelection, flag)
    },

    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      this.queryParam.pageCurrent = val
      this.GetMetaTaskList(this.queryParam)
    },
    /** 获取任务规划列表 */
    GetMetaTaskList(params, flag = false) {
      this.isAuto = flag
      this.tableLoading = true
      return GetMetaTaskList(params).then(res => {
        this.tableLoading = false
        this.tableData = res.data.data.records
        this.total = res.data.data.total
        if (flag) {
          // 如果是自动化，就把列表中所有的数据传递过去
          this.multipleSelection = this.tableData
          this.handleOpenModal(true) // 自动打开
        }
      })
    }
  }
}
</script>

<style></style>
